package com.mars.miaosha.util;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * commoms工具类中有MD5的包装方法
 * @author MARS
 * @date 2018/5/7
 */
@Slf4j
public class MD5Util {

    // 加盐值，保证密码安全性
    private static final String salt = "mars123";

    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    // md5加密方法
    public static String inputPassToFOrmPass(String inputPass) {
        String str = "" + salt.charAt(0) +  salt.charAt(1) + inputPass + salt.charAt(4) + salt.charAt(6);
        log.info("加salt后密码为：{}",str);
        return md5(str);
    }

    public static String formPassToDBPass(String formPass,String salt){
        String str = "" + salt.charAt(0) +  salt.charAt(1) + formPass + salt.charAt(4) + salt.charAt(6);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass,String salt){
        String formPass = inputPassToFOrmPass(inputPass);
        String dbPass = formPassToDBPass(formPass,salt);
        return dbPass;
    }

    public static void main(String[] args) {
//        String password1 = inputPassToFOrmPass("123456");

        log.info("二次MD5加密后密码为：{}",inputPassToDBPass("123456",salt));
    }
}
